package org.dtrd.modules.system.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.system.entity.bean.qiyeweixin.QwFollowUser;
import org.dtrd.modules.system.entity.po.DtrdEntRdQwClientFollow;
import org.dtrd.modules.system.mapper.DtrdEntRdQwClientFollowMapper;
import org.dtrd.modules.system.service.IDtrdEntRdQwClientFollowService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 萧
 * @date 2021-11-11 10:54:11
 **/
@Service
@DS("multi-datasource1")
public class DtrdEntRdQwClientFollowServiceImpl extends ServiceImpl<DtrdEntRdQwClientFollowMapper, DtrdEntRdQwClientFollow> implements IDtrdEntRdQwClientFollowService {

    @Override
    public void saveExternalFollowUser(List<QwFollowUser> followUsers, String externalUserid) {
        List<DtrdEntRdQwClientFollow> list = new ArrayList<>(followUsers.size());
        followUsers.stream().map(qf -> {
            DtrdEntRdQwClientFollow po = getRecordByExternalUserIdFollowUserId(externalUserid, qf.getUserid());
            if (po == null) {
                po = new DtrdEntRdQwClientFollow().init();
            }
            po.parseFromQwFollowUser(qf);
            po.setExternalUserid(externalUserid);
            return po;
        }).forEach(list::add);
        saveOrUpdateBatch(list);
    }

    @Override
    public DtrdEntRdQwClientFollow getRecordByExternalUserIdFollowUserId(String externalUserid, String followUserId) {
        return baseMapper.getRecordByExternalUserIdFollowUserId(externalUserid, followUserId);
    }


}
